home *** CD-ROM | disk | FTP | other *** search
/ Gigantic Games 2 / Gigantic Games 2.iso / pc / _c_ / cyber_flight / cyber_flight.c < prev    next >
C/C++ Source or Header  |  1994-12-22  |  9KB  |  310 lines

  1. /* Circuit Shootem Up - a GameSmith demo.  AGA ONLY! */
  2. /*
  3.     This program demonstrates use of AGA 7 bitplane dual playfield independent
  4.     scrolling (4 planes for playfield 1, and 3 for playfield 2).  I was gonna
  5.     use 8 bitplanes total, but any colors I added to the 2nd playfield just
  6.     detracted from the graphics.  I guess that's why I'm a programmer and
  7.     not a graphic artist. <grin>  The demo also uses a split screen as is
  8.     commonly found in many shoot'em up type games.  The bottom panel doesn't
  9.     do anything.  It's just there as an example.  -John Enright 4-15-94
  10. */
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <exec/memory.h>
  16. #include <exec/types.h>
  17. #include <graphics/gfx.h>
  18. #include <graphics/gfxbase.h>
  19.  
  20. #include <proto/exec.h>
  21. #include <proto/graphics.h>
  22. #include <proto/intuition.h>
  23.  
  24. #include "GameSmith:GameSmith.h"
  25. #include "GameSmith:include/proto/all_regargs.h"
  26. #include "GameSmith:include/libraries/libptrs.h"
  27.  
  28. #define BMWIDTH    640
  29. #define BMHEIGHT    400
  30.  
  31. #define PF1_PLANES    0x55;
  32. #define PF2_PLANES    0xaa;
  33. #define ALL_PLANES    0xff;
  34.  
  35. /*-------------------------------------------------------------------------*/
  36. /* Function Prototypes                                                                       */
  37.  
  38. void scroll(void);
  39. int setup(void);
  40. int check_close(void);
  41. void cleanup(void);
  42.  
  43. /*-------------------------------------------------------------------------*/
  44. /* some global variables                                                   */
  45.  
  46. struct Interrupt *scroller=NULL;
  47. unsigned long color[48];
  48.  
  49. /*-------------------------------------------------------------------------*/
  50.  
  51. struct loadILBM_struct loadpic =
  52.     {
  53.     NULL,                    /* ptr to picture name string */
  54.     NULL,                    /* ptr to 1st bitmap */
  55.     NULL,                    /* ptr to 2nd bitmap (if any) */
  56.     color,                /* ptr to color table array */
  57.     16,                    /* # colors in color table */
  58.     NULL,                    /* height of image in pixels (filled by load call) */
  59.     NULL,                    /* width of image in pixels (filled) */
  60.     NULL,                    /* x display offset (filled) */
  61.     NULL,                    /* y display offset (filled) */
  62.     NULL,                    /* pic mode (filled) */
  63.     0,                        /* x load offset (from left) in bytes */
  64.     0,                        /* y load offset (from top) in rows */
  65.     ILBM_COLOR,            /* flags (fill color table) */
  66.     0xff,                    /* bitplane fill mask */
  67.     0xff,                    /* bitplane load mask */
  68.     NULL                    /* address of BitMapHeader to fill (none) */
  69.     };
  70.  
  71. unsigned short copper_list[]= {
  72.     UC_NOSPRITES,                        /* turn off sprite DMA */
  73.     UC_END                                /* end custom copper list */
  74.     };
  75.  
  76. struct copper_struct copper = 
  77.     {
  78.     copper_list,
  79.     NULL,
  80.     NULL
  81.     };
  82.  
  83. struct gs_viewport vp2 =
  84.     {
  85.     NULL,                                    /* ptr to next viewport */
  86.     &color[32],                            /* ptr to color table */
  87.     16,                                    /* number of colors in table */
  88.     &copper,                                /* ptr to user copper list */
  89.     47,320,4,47,320,                    /* height, width, depth, bmheight, bmwidth */
  90.     153,0,                                /* top & left viewport offsets */
  91.     0,0,                                    /* X & Y bitmap offsets */
  92.     GSVP_ALLOCBM,                        /* flags (alloc bitmaps) */
  93.     NULL,NULL,                            /* 2.xx & above compatibility stuff */
  94.     NULL,NULL,                            /* bitmap pointers */
  95.     NULL,                                    /* future expansion */
  96.     0,0,0,0                                /* display clip (MinX,MinY,MaxX,MaxY) */
  97.     };
  98.  
  99. struct gs_viewport vp =
  100.     {
  101.     &vp2,                                    /* ptr to next viewport */
  102.     color,                                /* ptr to color table */
  103.     32,                                    /* number of colors in table */
  104.     NULL,                                    /* ptr to user copper list */
  105.     150,320,7,BMHEIGHT,BMWIDTH,    /* height, width, depth, bmheight, bmwidth */
  106.     0,0,                                    /* top & left viewport offsets */
  107.     0,0,                                    /* X & Y bitmap offsets */
  108.     GSVP_DPF|GSVP_ALLOCBM,             /* flags (dual playfield,alloc bitmaps) */
  109.     NULL,NULL,                            /* 2.xx & above compatibility stuff */
  110.     NULL,NULL,                            /* bitmap pointers */
  111.     NULL,                                    /* future expansion */
  112.     0,0,0,0                            /* display clip (MinX,MinY,MaxX,MaxY) */
  113.     };
  114.  
  115. struct display_struct display =
  116.     {
  117.     NULL,                                    /* ptr to previous display view */
  118.     NULL,NULL,                            /* 2.xx & above compatibility stuff */
  119.     0,0,                                    /* X and Y display offsets (1.3 style) */
  120.     0,                                        /* display mode ID */
  121.     GSV_SCROLLABLE,                    /* flags (scrollable) */
  122.     &vp,                                    /* ptr to 1st viewport */
  123.     NULL                                    /* future expansion */
  124.     };
  125.  
  126. /***************************************************************************/
  127.  
  128. main(argc,argv)
  129. int argc;
  130. char *argv[];
  131.  
  132. {
  133.     int err,end=0;
  134.  
  135.     if (gs_open_libs(DOS|GRAPHICS,0))    /* open AmigaDOS libs, latest versions */
  136.         exit(01);                    /* if can't open libs, abort */
  137.     if (err=setup())                /* if couldn't get set up... abort program */
  138.         {
  139.         printf("\nSetup error: %d\n",err);
  140.         gs_close_libs();            /* close all libraries */
  141.         exit(02);
  142.         }
  143.     Forbid();                        /* take over the entire machine */
  144.     while (!end)                    /* this shows off speed */
  145.         {
  146.         end=check_close();        /* end when user hits left mouse button */
  147.         }
  148.     Permit();                        /* OK, let other things run while we clean up */
  149.     cleanup();                        /* close & deallocate everything */
  150.     gs_close_libs();                /* close all libraries */
  151. }
  152.  
  153. /***************************************************************************/
  154.  
  155. void __interrupt __saveds scroll()
  156.  
  157. {
  158.     int stick,x=0,y=0,diff,velocity=2,x2,y2;
  159.     static int timer=0;
  160.     static int x_save=0,y_save=0;
  161.  
  162.     stick = _gs_joystick(1);
  163.     if (stick & (JOY_LEFT|JOY_RIGHT|JOY_UP|JOY_DOWN))
  164.         {
  165.         if (stick & JOY_BUTTON1)
  166.             velocity<<=1;
  167.         if (stick & JOY_LEFT)
  168.             x=velocity*-1;
  169.         else if (stick & JOY_RIGHT)
  170.             x=velocity;
  171.         if (stick & JOY_UP)
  172.             y=velocity*-1;
  173.         else if (stick & JOY_DOWN)
  174.             y=velocity;
  175.         timer=0;
  176.         }
  177.     else if (timer++ >= (60*5))                    /* 5 second timeout */
  178.         {
  179.         x=x_save;
  180.         y=y_save;
  181.         if (!x_save)
  182.             {
  183.             x=_gs_random(3)+2;
  184.             if (_gs_random(100) < 50)
  185.                 x*=-1;
  186.             x_save=x;
  187.             }
  188.         else if (_gs_random(1000) < 10)
  189.             {
  190.             x=_gs_random(3)+2;
  191.             if (_gs_random(100) < 50)
  192.                 x*=-1;
  193.             x_save=x;
  194.             }
  195.         if (!y_save)
  196.             {
  197.             y=_gs_random(2)+2;
  198.             if (_gs_random(100) < 50)
  199.                 y*=-1;
  200.             y_save=y;
  201.             }
  202.         else if (_gs_random(1000) < 10)
  203.             {
  204.             y=_gs_random(2)+2;
  205.             if (_gs_random(100) < 50)
  206.                 y*=-1;
  207.             y_save=y;
  208.             }
  209.         }
  210.     if (x || y)
  211.         {
  212.         x2=x;
  213.         y2=y;
  214.         diff=vp.xoff+x;
  215.         if (diff < 0)
  216.             x=(BMWIDTH>>1)+x;
  217.         else if ((diff+vp.width) >= BMWIDTH)
  218.             x=-((BMWIDTH>>1)-x);
  219.         diff=vp.yoff+y;
  220.         if (diff < 0)
  221.             y=(BMHEIGHT>>1)+y;
  222.         else if ((diff+vp.height) >= BMHEIGHT)
  223.             y=-((BMHEIGHT>>1)-y);
  224.         gs_scroll_vp_pf1(&display,0,x,y,1);    /* scroll viewport 0, synchronize */
  225.         x=x2>>1;
  226.         y=y2>>1;
  227.         diff=vp.xoff2+x;
  228.         if (diff < 0)
  229.             x=(BMWIDTH>>1)+x;
  230.         else if ((diff+vp.width) >= BMWIDTH)
  231.             x=-((BMWIDTH>>1)-x);
  232.         diff=vp.yoff2+y;
  233.         if (diff < 0)
  234.             y=(BMHEIGHT>>1)+y;
  235.         else if ((diff+vp.height) >= BMHEIGHT)
  236.             y=-((BMHEIGHT>>1)-y);
  237.         gs_scroll_vp_pf2(&display,0,x,y,1);    /* scroll viewport 0, synchronize */
  238.         }
  239. }
  240.  
  241. /***************************************************************************/
  242.  
  243. int setup()
  244.  
  245. {
  246.     loadpic.bitmap1=NULL;    /* no bitmap to fill.  NOTE: this will cause an error return */
  247.     loadpic.bitmap2=NULL;    /* but the color table is still filled */
  248.     loadpic.file="gfx/pf1.pic";
  249.     gs_get_ILBM_bm(&loadpic);            /* get color table */
  250.     loadpic.file="gfx/pf2.pic";
  251.     loadpic.color_table=&color[16];    /* load 2nd playfield colors */
  252.     loadpic.num_colors=16;                /* must reset after each load */
  253.     gs_get_ILBM_bm(&loadpic);            /* get color table */
  254.     loadpic.file="gfx/dashboard.brush";
  255.     loadpic.color_table=&color[32];    /* load 2nd viewport colors */
  256.     loadpic.num_colors=16;                /* must reset after each load */
  257.     gs_get_ILBM_bm(&loadpic);            /* get color table */
  258.     #ifdef NTSC_MONITOR_ID
  259.         display.modes = NTSC_MONITOR_ID;
  260.     #endif
  261.     if (gs_create_display(&display))
  262.         {
  263.         return(-1);
  264.         }
  265.     loadpic.flags=0;                        /* don't load color table */
  266.     loadpic.file="gfx/pf1.pic";
  267.     loadpic.bitmap1=vp.bitmap1;        /* address of bitmap to fill */
  268.     loadpic.fill=PF1_PLANES;
  269.     gs_loadILBM(&loadpic);                /* load the picture! */
  270.     loadpic.file="gfx/pf2.pic";
  271.     loadpic.fill=PF2_PLANES;
  272.     gs_loadILBM(&loadpic);                /* load the picture! */
  273.     loadpic.file="gfx/dashboard.brush";
  274.     loadpic.bitmap1=vp2.bitmap1;        /* address of bitmap to fill */
  275.     loadpic.fill=ALL_PLANES;;
  276.     gs_loadILBM(&loadpic);                /* load the picture! */
  277.     scroller=gs_add_vb_server(&scroll,0);
  278.     if (!scroller)
  279.         {
  280.         gs_remove_display(&display);
  281.         return(-2);
  282.         }
  283.     gs_show_display(&display,1);        /* show the display */
  284.     return(0);
  285. }
  286.  
  287. /***************************************************************************/
  288.  
  289. int check_close()
  290.  
  291. /* check for user input */
  292.  
  293. {
  294.     if (gs_joystick(0) & JOY_BUTTON1)
  295.         return(1);
  296.     return(0);
  297. }
  298.  
  299. /***************************************************************************/
  300.  
  301. void cleanup()
  302.  
  303. /* release all resources and memory */
  304.  
  305. {
  306.     if (scroller)
  307.         gs_remove_vb_server(scroller);
  308.     gs_remove_display(&display);
  309. }
  310.